﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using DAL;
using Utility;
namespace BUS
{
    public class Tbl_SanPham_BUS
    {
        public static Tbl_SanPham_Collection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            return spDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static Tbl_SanPham_Collection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            return spDAL.Get(cri.Criter, 0, 0, Tbl_SanPham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static Tbl_SanPham_Entities GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_SanPham_Columns.STT.ToString(), Condition.EQUAL, iD);
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            Tbl_SanPham_Collection spCollection = spDAL.Get(cri.Criter, 0, 0, Tbl_SanPham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (spCollection.Count > 0)
                return spCollection[0];
            return null;
        }
        public static Tbl_SanPham_Collection GetByIDDN(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_SanPham_Columns.DoanhNghiep.ToString(), Condition.EQUAL, iD);
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            return spDAL.Get(cri.Criter, 0, 0, Tbl_SanPham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static int GetByTinhTrang(string iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_SanPham_Columns.TinhTrang.ToString(), Condition.EQUAL, iD);
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            Tbl_SanPham_Collection spCollection = spDAL.Get(cri.Criter, 0, 0, Tbl_SanPham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (spCollection.Count > 0)
                return spCollection.Count;
            return 0;
        }
        public static int CountProductOfBusiness(int dn)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_SanPham_Columns.DoanhNghiep.ToString(), Condition.EQUAL, dn);
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            Tbl_SanPham_Collection spCollection = spDAL.Get(cri.Criter, 0, 0, Tbl_SanPham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (spCollection.Count > 0)
                return spCollection.Count;
            return 0;
        }
        public static int Insert(Tbl_SanPham_Entities sp)
        {
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
           return spDAL.insert(sp);
        }
        public static void Update1(Tbl_SanPham_Entities sp)
        {
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            spDAL.Update1(sp);
        }
        public static void Update2(Tbl_SanPham_Entities sp)
        {
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            spDAL.Update2(sp);
        }
        public static void Update_hethan(Tbl_SanPham_Entities sp)
        {
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            spDAL.Update_hethan(sp);
        }
        public static void Update_tinhtrang(Tbl_SanPham_Entities sp)
        {
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            spDAL.Update_TinhTrang(sp);
        }
        public static void Delete(int id)
        {
            Tbl_SanPham_DAL spDAL = new Tbl_SanPham_DAL();
            spDAL.Delete(id);
        }
    }
}
